﻿/// <reference path="TsLinq.d.ts" />

//
//  Default comparer for strings and numbers
//
class DefaultComparer<TItem> implements IComparer<TItem>{
    //  
    //  Returns a value which indicates wherever item1 is bigger, smaller or equal with item2. If -1 is returned, item1 is smaller, if 0 is returned, both are equal and if 1 is returned, item1 is bigger than item2.
    //
    compare(item1: TItem, item2: TItem): number {
        if (item1 < item2) return -1;
        if (item1 == item2) return 0;
        return 1;
    }
} 

//
//  This comparer gets the JSON string of the objects to compare and then compares this strings.
//
class JsonStringComparer<TItem> implements IComparer<TItem>{
    //  
    //  Returns a value which indicates wherever item1 is bigger, smaller or equal with item2. If -1 is returned, item1 is smaller, if 0 is returned, both are equal and if 1 is returned, item1 is bigger than item2.
    //
    compare(item1: TItem, item2: TItem): number {
        var i1: string = JSON.stringify(item1);
        var i2: string = JSON.stringify(item2);
        if (i1 < i2) return -1;
        if (i1 == i2) return 0;
        return 1;
    }
}